{template 'common/header'}
{template 'nav'}
{if $op == 'list'}
<div class="main panel panel-danger">
<div class="panel-heading ">
	轮数列表
</div>
	<div class="panel-body table-responsive">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
					<th>标题</th>
					<th>类型</th>
					<th>状态</th>
					<th>投票总数</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $vote}
				<tr>
				    <td>{$vote['title']}</td>
					<td>{if $vote['show_style']==1}文字投票{else}图片投票{/if}</td>
					<td>{if $vote['status']==1}未开始{elseif $vote['status']==2}进行中{else}已结束{/if}</td>
					<!--<td><div>开始时间{php echo date('Y-m-d H:i:s',$vote['vote_start_time'])}<br>结束时间{php echo date('Y-m-d H:i:s',$vote['vote_end_time'])}</div></td>-->
					<td>{php echo pdo_fetchcolumn("SELECT SUM(nums) FROM ".tablename($this->vote_xms_table)." WHERE rid=:rid AND weid=:weid AND fid=:fid",array(':rid'=>$rid,':weid'=>$weid,':fid'=>$vote['id']));}票</td>
					<td style="text-align:left;">
						<a href="{php echo $this->createWebUrl('vote_manage', array('id' => $id,'op' => 'post', 'vote_id' => $vote['id']))}" class="btn btn-success btn-sm" data-toggle="tooltip" data-placement="top" title="修改"><i class="fa fa-edit"></i></a>
						<a href="{php echo $this->createWebUrl('vote_record', array('id' => $id, 'vote_id' => $vote['id']))}"class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="投票记录" ><i class="fa fa-users"></i></a>
						<a href="{php echo $this->createWebUrl('vote_manage', array('id' => $id,'op' => 'del', 'vote_id' => $vote['id']))}"class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="删除" onclick="return confirm('删除将无法恢复，确认吗？');return false;"><i class="fa fa-times"></i></a>
					</td>
				</tr>
				{/loop}
			</tbody>
		</table>
		{$pager}
	</div>
</div>
<script>
	require(['bootstrap'],function($){
		$('.btn').hover(function(){
			$(this).tooltip('show');
		},function(){
			$(this).tooltip('hide');
		});
	});
</script>
{elseif $op == 'post'}

<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
		<input type="hidden" name="vote_id" value="{$vote['id']}" />
		<div class="panel panel-danger">
			<div class="panel-heading">
				添加投票
			</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2  control-label">投票类型</label>
					<div class="col-sm-9 ">
						<label class="radio-inline">
							<input type="radio" name="show_style" value="1"  {if $vote['show_style'] == '1'}checked="true"{/if}> 文字
						</label>
						<label class="radio-inline">
							<input type="radio" name="show_style" value="2"  {if $vote['show_style'] == '2'}checked="true"{/if}>图片
						</label>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2  control-label">投票状态</label>
					<div class="col-sm-9 ">
						<label class="radio-inline">
							<input type="radio" name="status" value="1"  {if $vote['status'] == '1'}checked="true"{/if}> 未开始
						</label>
						<label class="radio-inline">
							<input type="radio" name="status" value="2"  {if $vote['status'] == '2'}checked="true"{/if}>进行中
						</label>
						<label class="radio-inline">
							<input type="radio" name="status" value="3"  {if $vote['status'] == '3'}checked="true"{/if}>已结束
						</label>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span><span class="label label-success">网页标题</span></label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" id='title' name="title" class="form-control" value="{$vote['title']}" placeholder="网页标题"/>
						<span class="help-block">网页标题</span>
					</div>
				</div>
			   <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span><span class="label label-success">投票主题</span></label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" id='tagname' name="vote_zhuti" class="form-control" value="{$vote['vote_zhuti']}" placeholder="请填写投票主题"/>
						<span class="help-block">投票主题</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">投票图片</label>
					<div class="col-sm-9">
						{php echo tpl_form_field_image('vote_zhuti_img', $vote['vote_zhuti_img']);}
						<span class="help-block">投票图片 规格大小为720x400</span>
					</div>
				</div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">投票说明</label>
                    <div class="col-xs-12 col-sm-9">
                        {php echo tpl_ueditor('vote_zhuti_des',$vote['vote_zhuti_des'])}
									<span class="help-block">投票说明</span>
                    </div>
                </div>
				<div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">投票项</label>
				 <div class="col-xs-12 col-sm-9">
					<div class="panel panel-default live_advs">
										  	<div class="panel-heading">
												<a href="javascript:;" class="btn btn-success vote_add">添加投票选项</a>
										  
											</div>
										  <div class="panel-body">
										  <ul class="list-group" id="vote_lists">
												{if !empty($vote_xms)}
															  {loop $vote_xms $row}
																	<li class="list-group-item ng-scope" id="vote_box_{$row['id']}">
																	<input type="hidden" name="vote_xms_id[]" value="{$row['id']}" />
																	<div class="form-group">
																		
																		<div class="col-sm-9 col-xs-12  col-md-2">
																			<input type="text" id='tagname' name="vote_displayid[]" class="form-control" value="{$row['displayid']}" placeholder="排序"/>
																			
																		</div>
																		<label class="col-xs-12 col-sm-3 col-md-1 control-label">名称</label>
																		<div class="col-sm-9 col-xs-12  col-md-2 ">
																			<input type="text" id='tagname' name="vote_name[]" class="form-control" value="{$row['name']}" placeholder="名称"/>
																			
																		</div>
																		{if $row['show_style']==2}
																				<div class="col-sm-8  col-xs-12 col-md-3">
																					{php echo tpl_form_field_image('vote_img[]',$row['img']);}
																					
																				</div>
																		{/if}
																		<label class="col-xs-12 col-sm-3 col-md-1 control-label">票数</label>
																		<div class="col-sm-9 col-xs-12  col-md-2 ">
																			<input type="text" id='vote_xms_nums' name="vote_xms_nums[]" class="form-control" value="{$row['nums']}" placeholder="票数"/>
																			
																		</div>
																		<div class="col-sm-8  col-xs-12 col-md-1">
																				<a href="javascript:;" class="btn btn-danger" onclick="vote_delete_box2({$row['id']})" >删除</a>
																	    </div>
																	</div>
																	</li>
															 {/loop}
															 {/if}
										  </ul>
										  </div>
										  <div class="panel-footer">
												<a href="javascript:;" class="btn btn-success vote_add">添加投票选项</a>
										  
											</div>
									</div>
					</div>
				  </div>
				<!----->
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2  control-label">投票单/双选</label>
					<div class="col-sm-9 ">
						<label class="radio-inline">
							<input type="radio" name="vote_more" value="1" onclick="show_more1()" {if $vote['vote_more'] == '1'}checked="true"{/if}> 单选
						</label>
						<label class="radio-inline">
							<input type="radio" name="vote_more" value="2" onclick="show_more2()"  {if $vote['vote_more'] == '2'}checked="true"{/if}>多选
						</label>
					</div>
				</div>
				<div class="form-group choice_style" style="{if $vote['vote_more']==1}display:none{/if}">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span><span class="label label-danger">每个人最多选几个</span></label>
					<div class="col-sm-9">
						<input type="text" id='title' name="vote_nums" class="form-control" value="{$vote['vote_nums']}" placeholder="每个人最多选几个"/>
						<span class="help-block">每个人最多选几个</span>
					</div>
				</div>
				<div class="form-group" style="display:none">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">投票起止时间</label>
					<div class="col-sm-9">
									{php echo tpl_form_field_daterange('ac_times',array('start'=>date('Y-m-d H:i:s',empty($vote['vote_start_ttime'])?time():$vote['vote_start_ttime']),'end'=>date('Y-m-d H:i:s',empty($vote['vote_end_time'])?time()+3600*240:$vote['vote_end_time'])),true);}
						<span class="help-block">本次活动起止时间</strong></span>
					</div>
				</div>
			</div>
		</div>
<div class="form-group col-sm-12">
	<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
	<input type="hidden" name="token" value="{$_W['token']}" />
	</div>
	</form>
</div>
<div id="vote_displayid" style="display: none">	
		<div class="col-sm-9 col-xs-12 col-md-2">
			<input type="text"  name="vote_displayid[]" class="form-control"/>
		</div>
</div>
<div id="vote_name" style="display: none">
		<label class="col-xs-12 col-sm-3 col-md-1 control-label">名称</label>
		<div class="col-sm-9 col-xs-12 col-md-2">
			<input type="text" name="vote_name[]" class="form-control"/>
		</div>
</div>
<div id="vote_xm_nums" style="display: none">
		<label class="col-xs-12 col-sm-3 col-md-1 control-label">票数</label>
		<div class="col-sm-9 col-xs-12 col-md-2">
			<input type="text" name="vote_xms_nums[]" class="form-control" value="0"/>
		</div>
</div>
<div id="vote_img" style="display: none">	

			<div class="col-sm-8  col-xs-12 col-md-3">
				{php echo tpl_form_field_image('vote_img[]', '');}
			</div>
</div>
<script language='javascript'>
	function show_more1(){
	$(".choice_style").hide();
	}
	function show_more2(){
		$(".choice_style").show();
	}
	function formcheck() {
		if ($("#tagname").val()=='') {
			alert("请填写奖项!");
			return false;
		}
		if ($("#luck_name").val()=='') {
			alert("请填写奖品名称!");
			return false;
		}
		if ($("#tagNum").val()=='') {
			alert("请填写奖品数量!");
			return false;
		}
		return true;
	}
</script>
<script type="text/javascript">
$(function(){
$('.vote_add').on('click', function(){
		var vote_add = new Date().getTime();
		var content = '<li class="list-group-item ng-scope" id="vote_box_'+vote_add+'"><div class="form-group">';
		
		content += $("#vote_displayid").html();
		content += $("#vote_name").html();
		if($('input[name="show_style"]:checked').val()==2){
			content += $("#vote_img").html();
		}
		content += $("#vote_xm_nums").html();
		content += '<div class="col-sm-8  col-xs-12 col-md-1">';
				 content += '<a href="javascript:;" class="btn btn-danger" onclick="vote_delete_box1('+vote_add+')" >删除</a>';
					content += '</div>';
				content += '</div>';
		content += '</li>';

		$('#vote_lists').append(content);
		var list_length = $('#vote_lists li').length;
		$('#vote_lists li:last-child input:first').val(list_length);
		$('#vote_lists li:last-child input:last').val(0);
		
});
})
function vote_delete_box1(id){
	if(id){
		$("#vote_box_"+id).remove();
	}else{
		alert('id不存在');
	}
}
function vote_delete_box2(id){
	if(!confirm("删除将无法恢复、确认删除么？"))return false;
	if(id){
		$.post("{php echo $this->createWebUrl('vote_manage',array('op'=>'ajax','id'=>$rid))}",{vote_xm_id:id},
		  function(data){
			if(data.res==0){
			 $("#vote_box_"+id).remove();
			}else{
				alert('删除失败');
			}
		  },
		  "json");
		
	}else{
		alert('id不存在');
	}
}
</script>
{/if}
{template 'common/footer'}